package Test;

import com.config.JdbcConfig;
import com.config.MyBatisConfig;
import com.config.SpringConfig;
import com.domain.Announcement;
import com.mapper.AnnouncementMapper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;

import java.io.FileWriter;

//配置事务的回滚,对数据库的增删改都会回滚,便于测试用例的循环利用
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={SpringConfig.class, MyBatisConfig.class})
public class AnnouncementMapperTest {
    @Autowired
    private AnnouncementMapper announcementMapper;

    @Test
    public void findByIdTest(){
        System.out.println(announcementMapper.findById("1"));
        System.out.println(announcementMapper.findById("1").getContent());
    }

    @Test
    public void delAnnouncementTest(){
        System.out.println(announcementMapper.delAnnouncement("1"));
    }

    @Test
    public void addAnnouncementTest(){
        Announcement announcement=new Announcement();
        announcement.setTitle("a");
        announcement.setContent("aa");
        System.out.println(announcementMapper.addAnnouncement(announcement));
    }


    @Test
    public void searchAnnouncementTest(){
        System.out.println(announcementMapper.searchAnnouncement());
    }

    @Test
    public void editAnnouncementTest(){
        Announcement announcement=new Announcement();
        announcement.setId("1");
        announcement.setTitle("a");
        announcement.setContent("aa");                                 //改了类型，出错看这
        System.out.println(announcementMapper.editAnnouncement(announcement));
    }

}
